package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsOpenCourtMapper;
import net.anzhuo.entity.GsOpenCourt;
import net.anzhuo.service.GsOpenCourtService;
@Service
public class GsOpenCourtServiceImpl implements GsOpenCourtService {

	@Autowired
	private GsOpenCourtMapper gsOpenCourtMapper;
	
	@Override
	public GsOpenCourt getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsOpenCourtMapper.getById(id);
	}

	
	@Override
	public GsOpenCourt getByMd5(String md5) {
		// TODO Auto-generated method stub
		
		return gsOpenCourtMapper.getByMd5(md5);
	}
	
	@Override
	public List<GsOpenCourt> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsOpenCourtMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsOpenCourt> getListWithPage(GsOpenCourt gsOpenCourt) {
		PaginationVO<GsOpenCourt> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsOpenCourtMapper.getListWithPage(gsOpenCourt));
		paginationVO.setTotalCount(gsOpenCourtMapper.getCount(gsOpenCourt.getCoMd5()));
		paginationVO.setTotalPage(((gsOpenCourtMapper.getCount(gsOpenCourt.getCoMd5()) -1)  / gsOpenCourt.getPageSize()+1));
		paginationVO.setPageNo(gsOpenCourt.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsOpenCourt> getList() {
		// TODO Auto-generated method stub
		return  gsOpenCourtMapper.getList();
	}

	@Override
	public List<GsOpenCourt> getList(GsOpenCourt gsOpenCourt) {
		// TODO Auto-generated method stub
		return gsOpenCourtMapper.getListByQuery(gsOpenCourt);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsOpenCourt gsOpenCourt) {
		// TODO Auto-generated method stub
		gsOpenCourtMapper.update(gsOpenCourt);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsOpenCourt gsOpenCourt) {
		// TODO Auto-generated method stub
		gsOpenCourtMapper.save(gsOpenCourt);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsOpenCourt gsOpenCourt = gsOpenCourtMapper.getById(id);
		if (gsOpenCourt == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsOpenCourtMapper.update(gsOpenCourt);

	}

}
